package com.gxa.meiye.admin.shop.service.impl;

import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxa.meiye.admin.shop.mapper.ServiceManagementMapper;
import com.gxa.meiye.admin.shop.service.ServiceManagement;
import com.gxa.meiye.core.common.ResponseData;
import com.gxa.meiye.core.pojo.shopManagement.Project;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author cc
 * @PackageName meiye
 * @Package com.gxa.meiye.admin.shop.service.impl
 * @Date 2022/7/24 18:02
 * @Version 1.0
 */
@Service
public class ServiceManagementImpl extends ServiceImpl<ServiceManagementMapper,Project> implements ServiceManagement {

    @Autowired
    private ServiceManagementMapper serviceManagementMapper;

    @Override
    public List<Project> getAllService() {
        return serviceManagementMapper.selectAllService();
    }

    @Override
    public Integer getAllServiceCount() {
        return serviceManagementMapper.selectAllServiceCount();
    }

    @Override
    public Integer getByProjectName(String name) {
        return serviceManagementMapper.selectByProjectName(name);
    }

    @Override
    public void updateByProjectName(Project project) {
        serviceManagementMapper.updateByProjectName(project);
    }


    @Override
    public void saveAll(Project project) {
        serviceManagementMapper.insertAll(project);
    }

    @Override
    public ResponseData putOnSale(Integer[] ids) {
        ResponseData rd = new ResponseData();
        try{
            if(ids.length>0) {
                for(Integer id : ids){
                    serviceManagementMapper.putOnSale(id);
                }
                rd.setCode(200);
                rd.setMsg("上架成功");
            }
        }catch (Exception e){
            e.printStackTrace();
            rd.setCode(500);
            rd.setMsg("系统开小差，请联系管理员");
        }
        return rd;

    }

    @Override
    public ResponseData offTheShelf(Integer[] ids) {
        ResponseData rd = new ResponseData();
        try{
            if(ids.length>0) {
                for(Integer id : ids){
                    serviceManagementMapper.offTheShelf(id);
                }
                rd.setCode(200);
                rd.setMsg("下架成功");
            }
        }catch (Exception e){
            e.printStackTrace();
            rd.setCode(500);
            rd.setMsg("系统开小差，请联系管理员");
        }
        return rd;
    }

    @Override
    public ResponseData changeProject(Project project) {
        ResponseData rd = new ResponseData();
        Integer number = serviceManagementMapper.updateProjectByName(project);
        if(number!=0){
            rd.setCode(200);
            rd.setMsg("修改成功");
        }else {
            rd.setCode(500);
            rd.setMsg("系统开小差");
        }
        return rd;
    }
}
